///Replication materials

///Set working directory
cd "/Users/jwalsh/Library/CloudStorage/GoogleDrive-walshji@gmail.com/My Drive/Natural Resources and Conflict/Human Rights Project/Data Paper/JPR RHRV Accepted Version/Replication Materials"

///Open dataset
use rhr.dta

///Install packages as needed
ssc install heatplot, replace
ssc install palettes, replace
ssc install colrspace, replace
net install cleanplots, from("https://tdmize.github.io/data/cleanplots")
ssc install catplot, replace
ssc install coefplot, replace
net describe polychoric, from(http://staskolenikov.net/stata)

///Set plot scheme
set scheme cleanplots, perm

///Relabel variables
label define violation_s_label 0 "No Allegations" 1 "Allegations"
label values violation_s violation_s_label
label values violation_a violation_s_label

label define violations 0 "No Allegation" 1 "Occasional" 2 "Frequent"
label values rkillings_s violations
label values rtorture_s violations
label values rdetention_s violations
label values rproperty_s violations
label values rrecruitment_s violations
label values rsexual_s violations
label values rdisplace_s violations
label values rrestrict_s violations

label values rkillings_a violations
label values rtorture_a violations
label values rdetention_a violations
label values rproperty_a violations
label values rrecruitment_a violations
label values rsexual_a violations
label values rdisplace_a violations
label values rrestrict_a violations

/// Results reported in paper

///Figure 2: Rebel Human Rights Violations
graph bar (count), over(violation_s)  bar(1, color(grey)) intensity(10) blabel(bar) ///
ytitle("Count") ylabel(, angle(0))
graph export figure2.png, replace width(1000)

///Figure 3: Specific Violations by Rebel Groups

///Individual rebel violations
catplot rkillings_s, recast(bar) ytitle("Count") b1title("") title("Rebel Killings") bar(1, bcolor(grey)) intensity(10) ylabel(0(500)1500) name(rkillings, replace)
catplot rtorture_s, recast(bar) ytitle("Count") b1title("") title("Rebel Torture") bar(1, bcolor(grey)) intensity(10) ylabel(0(500)1500) name (rtorture, replace)
catplot rdetention_s, recast(bar) ytitle("Count") b1title("") title("Rebel Detention") bar(1, bcolor(grey)) intensity(10) ylabel(0(500)1500) name(rdetention, replace)
catplot rproperty_s, recast(bar) ytitle("Count") b1title("") title("Rebel Property") bar(1, bcolor(grey)) intensity(10) ylabel(0(500)1500) name(rproperty, replace)
catplot rrecruitment_s, recast(bar) ytitle("Count") b1title("") title("Rebel Forced Recruitment") bar(1, bcolor(grey)) intensity(10) ylabel(0(500)1500) name(rrecruitment, replace)
catplot rsexual_s, recast(bar) ytitle("Count") b1title("") title("Rebel Sexual Violence") bar(1, bcolor(grey)) intensity(10) ylabel(0(500)1500) name(rsexual, replace)
catplot rdisplace_s, recast(bar) ytitle("Count") b1title("") title("Rebel Forced Displacement") bar(1, bcolor(grey)) intensity(10) ylabel(0(500)1500) name(rdisplace, replace)
catplot rrestrict_s, recast(bar) ytitle("Count") b1title("") title("Rebel Movement Restriction") bar(1, bcolor(grey)) intensity(10) ylabel(0(500)1500) name(rrestrict, replace)

graph combine rkillings rtorture rdetention rproperty rrecruitment rsexual rdisplace rrestrict, col(2)
graph export figure3.png, replace width(1000)

///Table 2: Polychoric correlations among variables
polychoric rkillings_s rtorture_s rdetention_s rproperty_s rrecruitment_s rsexual_s rdisplace_s rrestrict_s

///Figure 5

///Clean up data
recode intensity (1 = 0) (2 = 1)
la var intensity "Intensity"
label define intensitylabels 0 "Minor Conflict" 1 "War"
label values intensity intensitylabels
rename intensity Intensity

la var incomp "Secessionist"
label define incomplabels 1 "Territory" 2 "Government" 3 "Territory and Government"
label values incomp incomplabels
rename incomp Secessionist
recode Secessionist (2 = 1) (1 = 2)

la var type "Internationalized"
label define typelabels 3 "Intrastate" 4 "Internationalized"
label values type typelabels
rename type Internationalized

tsset dyadid year
xtlogit violation_s Intensity Secessionist Internationalized if Secessionist < 3
coefplot, drop(_cons) xline(1) eform xtitle(Violations) xlabel(0(2)10) name(f4violation, replace)

xtlogit rkillings_s Intensity Secessionist Internationalized if Secessionist < 3
coefplot, drop(_cons) xline(1) eform xtitle(Killings) xlabel(0(2)10) name(f4rkillings, replace)

xtlogit rtorture_s Intensity Secessionist Internationalized if Secessionist < 3
coefplot, drop(_cons) xline(1) eform xtitle(Torture) xlabel(0(2)10) name(f4rtorture, replace)

xtlogit rdetention_s Intensity Secessionist Internationalized if Secessionist < 3
coefplot, drop(_cons) xline(1) eform xtitle(Detention) xlabel(0(2)10) name(f4rdetention, replace)

xtlogit rproperty_s Intensity Secessionist Internationalized if Secessionist < 3
coefplot, drop(_cons) xline(1) eform xtitle(Property) xlabel(0(2)10) name(f4rproperty, replace)

xtlogit rrecruitment_s Intensity Secessionist Internationalized if Secessionist < 3
coefplot, drop(_cons) xline(1) eform xtitle(Recruitment) xlabel(0(2)10) name(f4rrecruitment, replace)

xtlogit rsexual_s Intensity Secessionist Internationalized if Secessionist < 3
coefplot, drop(_cons) xline(1) eform xtitle(Sexual Violence) xlabel(0(2)10) name(f4rsexual, replace)

xtlogit rdisplace_s Intensity Secessionist Internationalized if Secessionist < 3
coefplot, drop(_cons) xline(1) eform xtitle(Displacement) xlabel(0(2)10) name(f4rdisplace, replace)

xtlogit rrestrict_s Intensity Secessionist Internationalized if Secessionist < 3
coefplot, drop(_cons) xline(1) eform xtitle(Movement Restriction) xlabel(0(2)10) name(f4rrestrict, replace)

graph combine f4violation f4rkillings f4rtorture f4rdetention f4rproperty f4rrecruitment f4rsexual f4rdisplace f4rrestrict, col(3)
graph export figure5.png, replace width(1000)

///Comparison with sexual violence variable from the SVAC
polychoric rsexual_s svac_s

///Figure 4
///Create dummy variables for each violation
gen rkillingsdummy = 0
replace rkillingsdummy = 1 if rkillings_s > 0

gen rtorturedummy = 0
replace rtorturedummy = 1 if rtorture_s > 0

gen rdetentiondummy = 0
replace rdetentiondummy = 1 if rdetention_s > 0

gen rpropertydummy = 0
replace rpropertydummy = 1 if rproperty_s > 0

gen rrecruitmentdummy = 0
replace rrecruitmentdummy = 1 if rrecruitment_s > 0

gen rsexualdummy = 0
replace rsexualdummy = 1 if rsexual_s > 0

gen rdisplacedummy = 0
replace rdisplacedummy = 1 if rdisplace_s > 0

gen rrestrictdummy = 0
replace rrestrictdummy = 1 if rrestrict_s > 0

///Comparison of killings in RHRV with UCDP one-sided violence data
tsset dyadid year
logit rkillingsdummy osv_dummy, r cluster(dyadid)

///Create time-series dataset
collapse violation_s rkillingsdummy rtorturedummy rdetentiondummy rpropertydummy rrecruitmentdummy rsexualdummy rdisplacedummy rrestrictdummy, by(year)
tsset year
tsline violation, ytitle("Proportion") xtitle("Any Violation") color(grey) ylabel(0(.25)1) name(violationyear, replace)
tsline rkillingsdummy, ytitle("Proportion") xtitle("Killings") color(grey) ylabel(0(.25)1) name(rkillingsyear, replace)
tsline rtorturedummy, ytitle("Proportion") xtitle("Torture") color(grey) ylabel(0(.25)1) name(rtortureyear, replace)
tsline rdetentiondummy, ytitle("Proportion") xtitle("Detention") color(grey) ylabel(0(.25)1) name(rdetentionyear, replace)
tsline rpropertydummy, ytitle("Proportion") xtitle("Property") color(grey) ylabel(0(.25)1) name(rpropertyyear, replace)
tsline rrecruitmentdummy, ytitle("Proportion") xtitle("Recruitment") color(grey) ylabel(0(.25)1) name(rrecruitmentyear, replace)
tsline rsexualdummy, ytitle("Proportion") xtitle("Sexual Violence") color(grey) ylabel(0(.25)1) name(rsexualyear, replace)
tsline rdisplacedummy, ytitle("Proportion") xtitle("Forced Displacement") color(grey) ylabel(0(.25)1) name(rdisplaceyear, replace)
tsline rrestrictdummy, ytitle("Proportion") xtitle("Movement Restriction") color(grey) ylabel(0(.25)1) name(rrestrictyear, replace)

///Create Figure 4
graph combine violationyear rkillingsyear rtortureyear rdetentionyear rpropertyyear rrecruitmentyear rsexualyear rdisplaceyear rrestrictyear, ///
col(3)
graph export figure4.png, replace width(1000)

save rhr.dta, replace
clear


///Results reported in online appendix

///Comparison of State Department and Amnesty Data reported in Appendix
use rhr.dta

///Polychloric correlations
polychoric rkillings_s rkillings_a
polychoric rtorture_s rtorture_a
polychoric rdetention_s rdetention_a
polychoric rproperty_s rproperty_a
polychoric rrecruitment_s rrecruitment_a
polychoric rsexual_s rsexual_a
polychoric rdisplace_s rdisplace_a
polychoric rrestrict_s rrestrict_a

///Tabulations of displacement and restriction variables
tab rdisplace_s rdisplace_a
tab rrestrict_s rrestrict_a

///Figure A1: Rebel Human Rights Violations
graph bar (count), over(violation_a)  bar(1, color(grey)) intensity(10) blabel(bar) ///
ytitle("Count") ylabel(, angle(0)) title("Figure A1: Rebel Human Rights Violations, 1990-2018")
graph export figure1_a.png, replace width(1000)

///Figure A2: Specific Violations by Rebel Groups

///Individual rebel violations
catplot rkillings_a, recast(bar) ytitle("Count") b1title("") title("Rebel Killings") bar(1, bcolor(grey)) intensity(10) ylabel(0(500)1500) name(rkillings, replace)
catplot rtorture_a, recast(bar) ytitle("Count") b1title("") title("Rebel Torture") bar(1, bcolor(grey)) intensity(10) ylabel(0(500)1500) name (rtorture, replace)
catplot rdetention_a, recast(bar) ytitle("Count") b1title("") title("Rebel Detention") bar(1, bcolor(grey)) intensity(10) ylabel(0(500)1500) name(rdetention, replace)
catplot rproperty_a, recast(bar) ytitle("Count") b1title("") title("Rebel Property") bar(1, bcolor(grey)) intensity(10) ylabel(0(500)1500) name(rproperty, replace)
catplot rrecruitment_a, recast(bar) ytitle("Count") b1title("") title("Rebel Forced Recruitment") bar(1, bcolor(grey)) intensity(10) ylabel(0(500)1500) name(rrecruitment, replace)
catplot rsexual_a, recast(bar) ytitle("Count") b1title("") title("Rebel Sexual Violence") bar(1, bcolor(grey)) intensity(10) ylabel(0(500)1500) name(rsexual, replace)
catplot rdisplace_a, recast(bar) ytitle("Count") b1title("") title("Rebel Forced Displacement") bar(1, bcolor(grey)) intensity(10) ylabel(0(500)1500) name(rdisplace, replace)
catplot rrestrict_a, recast(bar) ytitle("Count") b1title("") title("Rebel Movement Restriction") bar(1, bcolor(grey)) intensity(10) ylabel(0(500)1500) name(rrestrict, replace)

graph combine rkillings rtorture rdetention rproperty rrecruitment rsexual rdisplace rrestrict, col(2) title("Figure A2: Specific Violations, 1990-2018")
graph export figure2_a.png, replace width(1000)

///Table 1: Polychoric correlations among variables
polychoric rkillings_a rtorture_a rdetention_a rproperty_a rrecruitment_a rsexual_a rdisplace_a rrestrict_a

///Figure 4
xtset dyadid year
xtlogit violation_a intensity incomp type if incomp < 3
coefplot, drop(_cons) xline(1) eform xtitle(Violations) xlabel(0(2)10) name(f4violation, replace)

xtlogit rkillings_a intensity incomp type if incomp < 3
coefplot, drop(_cons) xline(1) eform xtitle(Killings) xlabel(0(2)10) name(f4rkillings, replace)

xtlogit rtorture_a intensity incomp type if incomp < 3
coefplot, drop(_cons) xline(1) eform xtitle(Torture) xlabel(0(2)10) name(f4rtorture, replace)

xtlogit rdetention_a intensity incomp type if incomp < 3
coefplot, drop(_cons) xline(1) eform xtitle(Detention) xlabel(0(2)10) name(f4rdetention, replace)

xtlogit rproperty_a intensity incomp type if incomp < 3
coefplot, drop(_cons) xline(1) eform xtitle(Property) xlabel(0(2)10) name(f4rproperty, replace)

xtlogit rrecruitment_a intensity incomp type if incomp < 3
coefplot, drop(_cons) xline(1) eform xtitle(Recruitment) xlabel(0(2)10) name(f4rrecruitment, replace)

xtlogit rsexual_a intensity incomp type if incomp < 3
coefplot, drop(_cons) xline(1) eform xtitle(Sexual Violence) xlabel(0(2)10) name(f4rsexual, replace)

xtlogit rdisplace_a intensity incomp type if incomp < 3
coefplot, drop(_cons) xline(1) eform xtitle(Displacement) xlabel(0(2)10) name(f4rdisplace, replace)

xtlogit rrestrict_a intensity incomp type if incomp < 3
coefplot, drop(_cons) xline(1) eform xtitle(Movement Restriction) xlabel(0(2)10) name(f4rrestrict, replace)

graph combine f4violation f4rkillings f4rtorture f4rdetention f4rproperty f4rrecruitment f4rsexual f4rdisplace f4rrestrict, col(3) title("Figure A4: Intensity, Incompatabilities, and Internationalization")
graph export figure4_a.png, replace width(1000)

///Comparison with sexual violence variable from the SVAC
polychoric rsexual_a svac_a

///Comparison of killings in RHRV with UCDP one-sided violence data
tetrachoric rkillingsdummy_a osv_dummy rtorturedummy

///Figure 3
///Create dummy variables for each violation

gen rkillingsdummy_a = 0
replace rkillingsdummy = 1 if rkillings_a > 0

gen rtorturedummy_a = 0
replace rtorturedummy = 1 if rtorture_a > 0

gen rdetentiondummy_a = 0
replace rdetentiondummy = 1 if rdetention_a > 0

gen rpropertydummy_a = 0
replace rpropertydummy = 1 if rproperty_a > 0

gen rrecruitmentdummy_a = 0
replace rrecruitmentdummy = 1 if rrecruitment_a > 0

gen rsexualdummy_a = 0
replace rsexualdummy = 1 if rsexual_a > 0

gen rdisplacedummy_a = 0
replace rdisplacedummy = 1 if rdisplace_a > 0

gen rrestrictdummy_a = 0
replace rrestrictdummy = 1 if rrestrict_a > 0

///Drop observations for 2018, for which there is no data from Amnesty
drop if year == 2018

///Create time-series dataset
collapse violation_a rkillingsdummy_a rtorturedummy_a rdetentiondummy_a rpropertydummy_a rrecruitmentdummy_a rsexualdummy_a rdisplacedummy_a rrestrictdummy_a, by(year)
tsset year
tsline violation_a, ytitle("Proportion") xtitle("Any Violation") color(grey) ylabel(0(.25)1) name(violationyear, replace)
tsline rkillingsdummy_a, ytitle("Proportion") xtitle("Killings") color(grey) ylabel(0(.25)1) name(rkillingsyear, replace)
tsline rtorturedummy_a, ytitle("Proportion") xtitle("Torture") color(grey) ylabel(0(.25)1) name(rtortureyear, replace)
tsline rdetentiondummy_a, ytitle("Proportion") xtitle("Detention") color(grey) ylabel(0(.25)1) name(rdetentionyear, replace)
tsline rpropertydummy_a, ytitle("Proportion") xtitle("Property") color(grey) ylabel(0(.25)1) name(rpropertyyear, replace)
tsline rrecruitmentdummy_a, ytitle("Proportion") xtitle("Recruitment") color(grey) ylabel(0(.25)1) name(rrecruitmentyear, replace)
tsline rsexualdummy_a, ytitle("Proportion") xtitle("Sexual Violence") color(grey) ylabel(0(.25)1) name(rsexualyear, replace)
tsline rdisplacedummy_a, ytitle("Proportion") xtitle("Forced Displacement") color(grey) ylabel(0(.25)1) name(rdisplaceyear, replace)
tsline rrestrictdummy_a, ytitle("Proportion") xtitle("Movement Restriction") color(grey) ylabel(0(.25)1) name(rrestrictyear, replace)

///Create Figure 3
graph combine violationyear rkillingsyear rtortureyear rdetentionyear rpropertyyear rrecruitmentyear rsexualyear rdisplaceyear rrestrictyear, ///
col(3) title("Figure A3: Violations Per Year, 1990-2018") 
graph export figure3_a.png, replace width(1000)

clear
